package policies

import (
	"context"
	"github.com/goravel/framework/auth/access"
	contractsaccess "github.com/goravel/framework/contracts/auth/access"
	"goravel/app/models"
)

type RefillcardPolicy struct {
}

func NewRefillcardPolicy() *RefillcardPolicy {
	return &RefillcardPolicy{}
}

func (r *RefillcardPolicy) Update(ctx context.Context, arguments map[string]any) contractsaccess.Response {
	user := ctx.Value("user").(models.User)
	refillcard := arguments["post"].(models.Refillcard)

	if user.ID == refillcard.UserID || user.IsAdmin() {
		return access.NewAllowResponse()
	} else {
		return access.NewDenyResponse("You do not own this  premium card.")
	}
}
